<template>
  <div class="wfull">
    <a-form :labelCol="{ span: 5 }" :wrapperCol="{ span: 19 }">
      <a-form-item label="头像">
        <ZgUpImg v-model="obj.head"></ZgUpImg>
      </a-form-item>
      <a-form-item label="所属组织" required>
        <ZgOrgSelect :multiple="false" v-model="orgIdArr"></ZgOrgSelect>
      </a-form-item>
      <a-form-item label="用户名" required>
        <ZgInput v-model="obj.username"></ZgInput>
      </a-form-item>
      <a-form-item label="姓名" required>
        <ZgInput v-model="obj.name"></ZgInput>
      </a-form-item>
      <a-form-item label="性别">
        <ZgDictionary code="sex" v-model="obj.sex"></ZgDictionary>
      </a-form-item>
      <a-form-item label="手机号" required>
        <ZgInput v-model="obj.phone"></ZgInput>
      </a-form-item>
      <a-form-item label="身份证">
        <ZgInput v-model="obj.idCard"></ZgInput>
      </a-form-item>
      <a-form-item label="邮箱">
        <ZgInput v-model="obj.email"></ZgInput>
      </a-form-item>
      <a-form-item label="生日">
        <ZgDatePicker v-model="obj.birth"></ZgDatePicker>
      </a-form-item>
      <a-form-item label="学历">
        <ZgDictionary code="eduLevel" v-model="obj.eduLevel"></ZgDictionary>
      </a-form-item>
      <a-form-item label="状态">
        <ZgSwitch v-model="obj.isOpen"></ZgSwitch>
      </a-form-item>
      <a-form-item label="标签">
        <ZgTags v-model="tags"></ZgTags>
      </a-form-item>
      <a-form-item label="简介">
        <a-textarea v-model="obj.intro" placeholder="请输入简介" :rows="4" />
      </a-form-item>
    </a-form>
  </div>
</template>
<script>
export default {
  data () {
    return {
      tags: [],
      orgIdArr: [],
      obj: {
        head: '',
        username: '',
        name: '',
        sex: '',
        phone: '',
        idCard: '',
        email: '',
        birth: '',
        isOpen: true,
        intro: ''
      }
    }
  },
  methods: {
    save () {
      if (this.orgIdArr.length === 0) {
        return this.$result.error('请选择所属组织')
      }
      if (this.obj.username.length === 0) {
        return this.$result.error('请输入用户名')
      }
      if (this.obj.name.length === 0) {
        return this.$result.error('请输入姓名')
      }
      if (this.obj.phone.length === 0) {
        return this.$result.error('请输入手机号')
      }

      return this.$result.ok(Object.assign({
        tags: this.tags.length > 0 ? this.tags.join(',') : '',
        orgId: this.orgIdArr[0]
      }, this.obj))
    }
  }
}
</script>

<style lang="scss" scoped>
.ant-form-item{
  margin-bottom:5px;
}
</style>
